package com.geekhalo.admin.menu;

import com.geekhalo.admin.app.menu.MenuCommandApplication;
import com.geekhalo.admin.app.menu.MenuQueryApplication;
import com.geekhalo.admin.app.menu.query.ListByAppId;
import com.geekhalo.admin.domain.menu.MenuView;
import com.geekhalo.lego.core.web.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("menu")
public class MenuController {
    @Autowired
    private MenuCommandApplication menuCommandApplication;

    @Autowired
    private MenuQueryApplication menuQueryApplication;

    @GetMapping("getByAppId")
    public RestResult<List<MenuDTO>> getByAppId(@RequestParam Long appId){
        ListByAppId listByAppId = new ListByAppId();
        listByAppId.setAppId(appId);
        List<MenuView> menuViews = this.menuQueryApplication.listOf(listByAppId);
        List<MenuDTO> menuDTOS = MenuDTO.from(menuViews);
        return RestResult.success(menuDTOS);
    }
}
